package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 执行查询操作
 */
public class JDBCDemo5 {
    public static void main(String[] args) {
        //需求:查看所有老师的名字,工资,性别,职称
        try(
                Connection connection = DBUtil.getConnection();
        ) {
            Statement statement = connection.createStatement();
            /*
                SELECT name,salary,gender,title
                FROM teacher
             */
            String sql = "SELECT name,salary,gender,title " +
                         "FROM teacher";
            /*
                Statement提供了用于执行DQL语句的方法
                ResultSet executeQuery(String sql)
             */
            ResultSet rs = statement.executeQuery(sql);
            while(rs.next()){
                String name = rs.getString("name");
                int salary = rs.getInt("salary");
                String gender = rs.getString("gender");
                String title = rs.getString("title");
                System.out.println(name+","+salary+","+gender+","+title);
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}









